<template>
  <view class="type">
    <div class="nav">
      <uni-icons
        class="icon"
        @click="huitui"
        color="#fff"
        ;
        type="back"
        size="20"
      ></uni-icons>
      <text class="fabu">房产类型</text>
    </div>

    <view class="box2">
      <img
        class="imgss"
        src="https://img0.baidu.com/it/u=1525335554,2645312724&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=727"
        alt=""
      />

      <view class="scroll">
        <uni-title
          color="#fff"
          type="h2"
          title="请选择房间类型"
          align="center"
        ></uni-title>

        <view class="bottn">
          <view class="b1" v-for="(item, index) in dataTree" :key="index"  @click="navtiage(item.id)">
            {{ item.useto }}
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";
const path = uni.getStorageSync("path");
const huitui = () => {
  uni.navigateTo({ url: path });
};

const dataTree = ref();
// 请求数据
onMounted(() => {
  const address = [];
  //  储存小区数据
  uni.request({
    url: "http://10.31.71.52:7002/housing",
    method: "GET",
    success: (res) => {
      console.log(res.data.data);
      let data = res.data.data;
      console.log(data);
      for (let i = 0; i < data.length; i++) {
        address.push(data[i]);
      }
      dataTree.value = address;
    },
  });
});

const paths = uni.getStorageSync('path');

//  页面回显
const navtiage =(id)=>{
   const newdata = dataTree.value.find(item=>item.id ===id);
    // console.log(,'===============newdata');
    const data = newdata.useto
    uni.navigateTo({url:paths + '?data=' + `${data}`});
    uni.setStorageSync("types", data);
};
</script>

<style lang="scss">
.type {
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  // position: relative;
  .imgss {
    width: 100%;
    height: 100%;
  }
  .box2 {
    flex: 1;
    position: relative;
    .scroll {
      width: 100%;
      height: 100%;
      background: rgba(33, 31, 31, 0.4);
      position: absolute;
      top: 0;
      left: 0;
    }
  }
  .nav {
    width: 100vw;
    height: 100px;
    background: linear-gradient(to right, #3e85ef, rgb(46, 175, 255));
    position: relative;
    .fabu {
      position: absolute;
      left: 50%;
      top: 60%;
      transform: translate(-50%, -50%);
      color: #fff;
    }
    .icon {
      position: absolute;
      top: 50%;
      left: 10px;
    }
  }
  .bottn {
    width: 100vw;
    height: 200px;
    background-color: #fff;
    position: absolute;
    bottom: 0;
    left: 0;
    overflow: auto;
    box-shadow: 0 5px 15px 5px #000000;
    .b1 {
      width: 100vw;
      height: 30px;
      border-top: 1px solid #ccc;
      text-align: center;
      line-height: 30px;
      background: linear-gradient(to bottom, #f9f5f5, #f4f4f4);
    }
  }
}
</style>
